package cn.itcast.crawler.test;

import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

import java.io.IOException;


public class CrawlerFirst {
    public static void main(String[] args) throws Exception {
        //1.打开浏览器，创建HTTPClient对象
        CloseableHttpClient httpClient = HttpClients.createDefault();

        //2.输入网址
        HttpGet httpget = new HttpGet("https://ing.cnblogs.com/");

        //3.按回车，发起请求，返回响应
        CloseableHttpResponse response = httpClient.execute(httpget);

        //4.解析响应，获取数据
        if(response.getStatusLine().getStatusCode() == 200){ //判断状态码是否是200
            HttpEntity httpentity = response.getEntity();
            String content= EntityUtils.toString(httpentity, "utf8");
            System.out.println(content);
        }

    }
}
